package com.xxcxcxcx.jobsystem.mixin.ui;

import com.mojang.blaze3d.vertex.PoseStack;
import com.xxcxcxcx.jobsystem.common.UI.JobUI;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.entity.player.Player;
import org.lwjgl.system.CallbackI;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InventoryScreen.class)
public class InventoryScreenMixin extends Screen {
    Button JobButton;

    protected InventoryScreenMixin(Component p_96550_) {
        super(p_96550_);
    }
    @Shadow
    private final RecipeBookComponent recipeBookComponent = new RecipeBookComponent();
    @Inject(method = "init",at = @At(value = "RETURN"))
    public void initmixin(CallbackInfo ci) {
        JobButton = new Button(this.width/2-104,this.height/2-83,16,16, new TextComponent("J"),(button)->{
            Minecraft.getInstance().setScreen(new JobUI(new TextComponent("Job UI")));
        });
        this.addWidget(JobButton);
    }
    @Inject(method = "render",at = @At(value = "RETURN"))
    public void rendermixin(PoseStack poseStack, int MouseX, int MouseY, float partialTicks,CallbackInfo ci) {
        if(recipeBookComponent.isVisible())
        {
            JobButton.x=this.width/2;
            JobButton.y=this.height/2-99;
        }
        else
        {
            JobButton.x=this.width/2-104;
            JobButton.y=this.height/2-83;
        }
        JobButton.render(poseStack,MouseX,MouseY,partialTicks);
    }
}
